package com.mugui.bean;

import java.io.IOException;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;

public class DataSerializer implements ObjectSerializer {

	private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

	@Override
	public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) {
		if (object instanceof Date){
			serializer.write(dateFormat.format((Date) object));
		}
		else if (object instanceof BigDecimal)
			serializer.write(((BigDecimal) object).stripTrailingZeros().toPlainString());

	}

}
